package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.StrategyCommend;
import cn.wolfcode.luowowo.article.mapper.StrategyCommendMapper;
import cn.wolfcode.luowowo.article.service.IStrategyCommendService;
import cn.wolfcode.luowowo.common.query.QueryObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
@Service
public class StrategyCommendServiceImpl implements IStrategyCommendService {

    @Autowired
    private StrategyCommendMapper strategyCommendMapper;
    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),"sequence asc");
        List<StrategyCommend> list = strategyCommendMapper.selecForList(qo);
        return new PageInfo(list);
    }

    @Override
    public void save(StrategyCommend strategyCommend) {
        //自动生成序号
        //判断是否有序号
        if(strategyCommend.getSequence() == null){
            //查询最大的序号值
            int maxSequence = strategyCommendMapper.selectMaxSequence();
            strategyCommend.setSequence(maxSequence + 1);
        }
        strategyCommendMapper.insert(strategyCommend);
    }


    @Override
    public List<StrategyCommend> listTop5() {
        return strategyCommendMapper.listTop5();
    }
}
